package com.publicize.controller;


import com.publicize.commom.commonutils.Result;
import com.publicize.entity.ModulePicture;
import com.publicize.service.ModulePictureService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.List;

/**
 * <p>
 * 富文本编辑器图片路径 前端控制器
 * </p>
 *
 * @author bs
 * @since 2021-03-16
 */
@CrossOrigin
@RestController
@RequestMapping("/proscenium/module-picture")
public class ModulePictureController {
    @Autowired
    private ModulePictureService modulePictureService;
    @GetMapping("{moduleId}")
    public Result getByModuleId(@PathVariable String moduleId){
        return Result.ok().data("modulePictures",modulePictureService.queryByModuleId(moduleId));
    }
    @PostMapping("{moduleId}")
    public Result addByModuleId(@RequestBody List<ModulePicture> modulePictures, @PathVariable String moduleId){
    for (ModulePicture modulePicture : modulePictures) {
      modulePicture.setModuleId(moduleId);
    }
        modulePictureService.saveBatch(modulePictures);
        return Result.ok();
    }
}

